From 41eae921c515d43ae303e8f023460d25e41625ed Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Thu, 30 May 2019 15:10:53 -0600 Subject: [PATCH] fix potential memory leaks. (#365) * fix potential memory leaks. * fix more memory leaks. A method to find these is to add -DQT_ASCII_CAST_WARNINGS and then look for xstrdup in the warnings. * a few cleanups clazy caught. --- g7towin.cc | 2 +- gdb.cc | 2 +- html.cc | 5 ++- navilink.cc | 2 +- ozi.cc | 4 +- reference/gc/GCGCA8_logs~html.txt | 64 +++++++++++++++++++++++++++++++ testo.d/text.test | 3 ++ tmpro.cc | 4 +- xcsv.cc | 7 +--- 9 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 reference/gc/GCGCA8_logs~html.txt diff --git a/g7towin.cc b/g7towin.cc index ac1c15d9c..1e575cb1e 100644 --- a/g7towin.cc +++ b/g7towin.cc @@ -510,7 +510,7 @@ data_read() break; case 'L': - waypt_add_url(wpt, xstrdup(cdata), nullptr); + waypt_add_url(wpt, cdata, nullptr); break; default: diff --git a/gdb.cc b/gdb.cc index 9e948136a..5b1f95f0c 100644 --- a/gdb.cc +++ b/gdb.cc @@ -394,7 +394,7 @@ gdb_write_cstr_list(const char* str) static void gdb_write_cstr_list(const QString& str) { - return gdb_write_cstr_list(CSTRc(str)); + gdb_write_cstr_list(CSTRc(str)); } static void diff --git a/html.cc b/html.cc index 38df26bf2..144180ee4 100644 --- a/html.cc +++ b/html.cc @@ -215,11 +215,12 @@ html_disp(const Waypoint* wpt) if (html_encrypt && encoded) { s = rot13(logpart->cdata); } else { - s = xstrdup(logpart->cdata); + s = logpart->cdata; } - QString t = html_entitize(s); + char* t = html_entitize(s); gbfputs(t, file_out); + xfree(t); } gbfprintf(file_out, "

\n"); diff --git a/navilink.cc b/navilink.cc index 6f3f43155..b7df0c1b3 100644 --- a/navilink.cc +++ b/navilink.cc @@ -660,7 +660,7 @@ serial_read_routes(Waypoint** waypts) route_head* route = route_head_alloc(); route->rte_num = routedata[2]; - route->rte_name = xstrdup((char*)routedata + 4); + route->rte_name = (char*)routedata + 4; route_add_head(route); for (int sr = 0; sr < MAX_SUBROUTES; sr++) { diff --git a/ozi.cc b/ozi.cc index 964e4ab8d..e5f3d1a1d 100644 --- a/ozi.cc +++ b/ozi.cc @@ -903,7 +903,7 @@ ozi_waypt_pr(const Waypoint* wpt) } } else { /* no description available */ - shortname = xstrdup(""); + shortname = ""; } } else { shortname = csv_stringclean(wpt->shortname, BADCHARS); @@ -912,7 +912,7 @@ ozi_waypt_pr(const Waypoint* wpt) if (!shortname.isEmpty()) { description = csv_stringclean(shortname, BADCHARS); } else { - description = xstrdup(""); + description = ""; } } else { description = csv_stringclean(wpt->description, BADCHARS); diff --git a/reference/gc/GCGCA8_logs~html.txt b/reference/gc/GCGCA8_logs~html.txt new file mode 100644 index 000000000..e5bac5a79 --- /dev/null +++ b/reference/gc/GCGCA8_logs~html.txt @@ -0,0 +1,64 @@ + + + + + GPSBabel HTML Output + + + +

+GCGCA8 - Oozy rat in a sanitary zoo
+

+ +
+ + + +

GCGCA8 - N35°55.300 W86°51.700 (16S 512480 3975269)
+Oozy rat in a sanitary zoo by robertlipe

3 / 2
+Unknown Cache / Unknown

The cache is not at the coordinates above. These coords will get you to the correct park and within 1/2 mile of the cache. The cache is within 35 feet of the trail. It is not handicapped accessible. It is a nice walk in the woods that is practical for all ages. There is no space in the container for trading items. You should bring a writing stick and bug spray is recommended.

+

So if the cache isn't at the above coordinates, where is it? + +

    + +
  • Too bad I hid a boot +
  • Too hot to hoot +
  • Never odd or even +
  • Do geese see God? +
  • "Do nine men interpret?" "Nine men," I nod +
  • Rats live on no evil star +
  • Go hang a salami, I'm a lasagna hog +
+ +Now that it's intuitively obvious to even the most casual observer where the cache is, turn on your geo-mojo and go find it. +
+Member of Middle Tennessee GeoCachers Club [www.mtgc.org]

+

Hint: There Is No Hint

+

+Found it by littlepod on 2005-07-03
+Enjoyed the puzzle. We seemed to be about 50ft off though. TFTC.

+

+Write note by robertlipe on 2005-04-29
+TB Drop to show he's hanging out in Nashville until we blast off for Geowoodstock in a few weeks.

+

+Found it by Big Bumblebee on 2005-04-18
+Found it a while ago. Thanks.

+

+Write note by robertlipe on 2005-03-27
+I had to renew my permit with the CDC and in doing so, I trolled out here verified that the infectious ooze is fully within specification and industry accepted tolerance. Ooze On!

+

+Found it by Virtual Babe on 2004-12-27
+This was a great cache, however on this day I considered it a FIFM cache (Fun, Invigorating, Frustrating and Maddening), especially when the cache was not replaced in the proper spot by the previous cacher! Thanks anyway!!

+

+Write note by robertlipe on 2004-01-12
+I got a complaint from the CDC about oozy rat this weekend. I went out tonight in the dark and verified that the infectious ooze is fully within specification and industry accepted tolerance. (Although I realize now I did misstate the cache container to the reporting officer when confronted. It's, uuuuh, smaller than I said.)

+

+Write note by robertlipe on 2003-10-04
+In the expectation that this cache will get some traffic in the next 48 hours, Ryan and I checked it earlier today. The Rat is Oozing just as we planned it.

+

+Write note by robertlipe on 2003-07-03
+It won't earn him a smiley face, but I've confirmed that rickrich would have indeed sunk the battleship! Thanx for playing. You get a copy of the home game and some rice-a-roni...

+
+ \ No newline at end of file diff --git a/testo.d/text.test b/testo.d/text.test index 71ce40ebb..df5bbbc55 100644 --- a/testo.d/text.test +++ b/testo.d/text.test @@ -7,3 +7,6 @@ gpsbabel -i gpx -f ${REFERENCE}/gc/GCGCA8.gpx \ compare ${REFERENCE}/gc/GCGCA8~text.txt ${TMPDIR}/gc.txt compare ${REFERENCE}/gc/GCGCA8~text-encoded.txt ${TMPDIR}/gc-encoded.txt compare ${REFERENCE}/gc/GCGCA8~html.txt ${TMPDIR}/gc.html + +gpsbabel -i gpx -f ${REFERENCE}/gc/GCGCA8.gpx -o html,logs -F ${TMPDIR}/gc_logs.html +compare ${REFERENCE}/gc/GCGCA8_logs~html.txt ${TMPDIR}/gc_logs.html diff --git a/tmpro.cc b/tmpro.cc index e18607f4d..b968e4953 100644 --- a/tmpro.cc +++ b/tmpro.cc @@ -182,7 +182,7 @@ tmpro_waypt_pr(const Waypoint* wpt) } } else { /* no description available */ - shortname = xstrdup(""); + shortname = ""; } } else { shortname = csv_stringclean(wpt->shortname, ",\""); @@ -192,7 +192,7 @@ tmpro_waypt_pr(const Waypoint* wpt) if (!shortname.isEmpty()) { description = csv_stringclean(shortname, ",\""); } else { - description = xstrdup(""); + description = ""; } } else { description = csv_stringclean(wpt->description, ",\""); diff --git a/xcsv.cc b/xcsv.cc index 2526be075..1d6dbb19e 100644 --- a/xcsv.cc +++ b/xcsv.cc @@ -180,9 +180,6 @@ typedef enum { /* obligatory global struct */ /****************************************************************************/ -extern char* xcsv_urlbase; -extern char* prefer_shortnames; - XcsvFile xcsv_file; static double pathdist = 0; static double oldlon = 999; @@ -209,8 +206,8 @@ static char* snlenopt = nullptr; static char* snwhiteopt = nullptr; static char* snupperopt = nullptr; static char* snuniqueopt = nullptr; -char* prefer_shortnames = nullptr; -char* xcsv_urlbase = nullptr; +static char* prefer_shortnames = nullptr; +static char* xcsv_urlbase = nullptr; static char* opt_datum; static const char* intstylebuf = nullptr; -- 2.30.2